# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import wx                        # This module uses the new wx namespace

_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

#---------------------------------------------------------------------------

class My_SaveDialog(wx.Dialog):
    def __init__(self, parent, title, pos=wx.DefaultPosition,
                 size=wx.DefaultSize):

        wx.Dialog.__init__(self, parent, -1, title, pos, size)
        
        #-------------------------------------------------------------------
        
        self.parent = parent
        
        #-------------------------------------------------------------------

        # Simplified init method
        self.create_widget()
        self.do_layout()

        #-------------------------------------------------------------------
        
        self.Centre(wx.BOTH)
        
        #-------------------------------------------------------------------
        
        self.ReturnValue = self.ShowModal()
        self.Destroy()

    #-----------------------------------------------------------------------
        
    def create_widget(self):                
        # dialogicon = images.Icon_Save.GetIcon()
        # dialogicon = wx.Icon("Icons/Icon_Save.ico", wx.BITMAP_TYPE_ICO)
        # self.SetIcon(dialogicon)
        
        #-------------------------------------------------------------------

        self.txt = wx.StaticText(self, -1,
                                 label=_("Enter the support name :"),
                                 style=wx.ALIGN_LEFT)
        
        #-------------------------------------------------------------------
        
        self.line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)

        #-------------------------------------------------------------------
        
        self.field = wx.TextCtrl(self, -1, value="", size=(310, -1),
                                 style=wx.TE_LEFT | wx.BORDER_THEME)

        if wx.Platform == "__WXMSW__":
            self.field.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD)) 
            
        self.field.SetForegroundColour("#e2001a")
        self.field.SetBackgroundColour("#ffffbe")
        self.field.SetFocus()
        
        # Bind a text event to an events handler
        self.Bind(wx.EVT_TEXT, self.evt_text, self.field)      

        #-------------------------------------------------------------------
        
        self.btnOK = wx.Button(self, id=wx.ID_OK, label="")

        self.btnCancel = wx.Button(self, id=wx.ID_CANCEL, label="")
        
        # Bind a button event to an events handler
        self.Bind(wx.EVT_BUTTON, self.on_ok, self.btnOK)
        self.Bind(wx.EVT_BUTTON, self.on_cancel, self.btnCancel)

        self.btnOK.SetDefault()
        
  #-----------------------------------------------------------------------        

    def do_layout(self):        
        imgSizer = wx.BoxSizer(wx.VERTICAL)
        txtSizer = wx.BoxSizer(wx.VERTICAL)
        imgTxtSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        
        #----------
        
        # imgSizer.Add(self.logo, 0, wx.ALL, 5)
        txtSizer.Add(self.txt, 0, wx.ALL, 5)
        txtSizer.Add(self.field, 1, wx.ALL | wx.EXPAND, 5)
        # imgTxtSizer.Add(imgSizer, 0, wx.ALIGN_CENTER, 0)
        imgTxtSizer.Add(txtSizer, 1, wx.ALL, 0)
        lineSizer.Add(self.line, 1, wx.ALL, 0)
        btnSizer.Add(self.btnOK, 0, wx.ALL, 10)
        btnSizer.Add(self.btnCancel, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 10)
        
        #----------
        
        mainSizer.Add(imgTxtSizer, 1, wx.ALL | wx.EXPAND, 5)
        mainSizer.Add(lineSizer, 0, wx.ALIGN_CENTRE | wx.EXPAND, 0)
        mainSizer.Add(btnSizer, 0, wx.ALIGN_RIGHT)
        
        #----------
        
        self.SetAutoLayout(True)
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        
    #-----------------------------------------------------------------------
        
    def GetValue(self):
        return self.field.GetValue()
     
     
    def evt_text(self, event):
        MonTexte = self.field.GetValue()
        ip = self.field.GetInsertionPoint()
        MonTexteUpper = MonTexte.upper()
        self.field.ChangeValue(MonTexteUpper)
        self.field.SetInsertionPoint(ip)
        event.Skip()

		
    def PressedButton(self):
        return self.ReturnValue

	
    def on_ok(self, event):
        self.EndModal(1)

     
    def on_cancel(self, event):
        self.EndModal(2)


